<?php

declare(strict_types=1);

namespace App\Amqp\Consumers;

use App\FundConf;
use App\Model\UserTest;
use App\Service\HscoinBillService;
use Hyperf\Amqp\Annotation\Consumer;
use Hyperf\Amqp\Message\ConsumerMessage;
use Hyperf\Amqp\Result;
use Hyperf\Contract\StdoutLoggerInterface;
use PhpAmqpLib\Message\AMQPMessage;
use App\Service\FundBillService;
use Hyperf\Di\Annotation\Inject;

#[Consumer(exchange: "user", routingKey: "user", queue: "user", nums: 1, enable: true)]
class UserConsumer extends ConsumerMessage
{
    #[Inject]
    private HscoinBillService $billService;

    #[Inject]
    private StdoutLoggerInterface $logger;

    public function consumeMessage($queueData, AMQPMessage $message): Result
    {
        $opt = $queueData['opt'] ?? [];
        $data = $queueData['data'] ?? [];
        $this->logger->info(print_r($data, true));
        $item = [
            'uid' => $data['uid'],
            'category' => '兑换的现金',
            'amount' => $data['result_amount'],
            'mark' => '兑换现金id' . $data['id'] . '价格' . $data['price'] . '金豆' . $data['hscoin_amount'] . '手续费' . $data['fee'],
        ];
        UserTest::create($item);
        $item = [
            'uid' => $data['uid'],
            'category' => '兑换的手续费',
            'amount' => $data['fee'],
            'mark' => '兑换现金手续费id' . $data['id'] . '价格' . $data['price'] . '金豆' . $data['hscoin_amount'] . '手续费' . $data['fee'],
        ];
        UserTest::create($item);
        return Result::ACK;


    }

    public function isEnable(): bool
    {
        return parent::isEnable();
    }
}
